var a = require("../../../api.js"), o = getApp()
Component({
  properties: {
    props: { // 属性名
      type: Array,
      value: ''
    }
  },

  observers: {

  },

  data: {
    carNumArr:'',
    newcarnum:'',
    itemActiveIndex: 0,
    showAddCarNum: false,
    keyboard1: [
      { name: '京', disabled: false }, { name: '津', disabled: false },
      { name: '晋', disabled: false }, { name: '冀', disabled: false },
      { name: '蒙', disabled: false }, { name: '辽', disabled: false },
      { name: '吉', disabled: false }, { name: '黑', disabled: false },
      { name: '沪', disabled: false }, { name: '苏', disabled: false },
      { name: '浙', disabled: false }, { name: '皖', disabled: false },
      { name: '闽', disabled: false }, { name: '赣', disabled: false },
      { name: '鲁', disabled: false }, { name: '豫', disabled: false },
      { name: '鄂', disabled: false }, { name: '湘', disabled: false },
      { name: '粤', disabled: false }, { name: '桂', disabled: false },
      { name: '琼', disabled: false }, { name: '渝', disabled: false },
      { name: '川', disabled: false }, { name: '贵', disabled: false },
      { name: '云', disabled: false }, { name: '藏', disabled: false },
      { name: '陕', disabled: false }, { name: '甘', disabled: false },
      { name: '青', disabled: false }, { name: '宁', disabled: false },
      { name: '新', disabled: false }, { name: 'W', disabled: false },
      { name: '', disabled: true }, { name: '', disabled: true },
      { name: '', disabled: true }, { name: '', disabled: true },
      { name: '', disabled: true }, { name: '', disabled: true },
      { name: '', disabled: true }
    ],

    keyboard2: [
      { name: '1', disabled: true }, { name: '2', disabled: true },
      { name: '3', disabled: true }, { name: '4', disabled: true },
      { name: '5', disabled: true }, { name: '6', disabled: true },
      { name: '7', disabled: true }, { name: '8', disabled: true },
      { name: '9', disabled: true }, { name: '0', disabled: true },
      { name: 'Q', disabled: false }, { name: 'W', disabled: false },
      { name: 'E', disabled: false }, { name: 'R', disabled: false },
      { name: 'T', disabled: false }, { name: 'Y', disabled: false },
      { name: 'U', disabled: false }, { name: 'O', disabled: false },
      { name: 'P', disabled: false }, { name: '军', disabled: true },
      { name: 'A', disabled: false }, { name: 'S', disabled: false },
      { name: 'D', disabled: false }, { name: 'F', disabled: false },
      { name: 'J', disabled: false }, { name: 'K', disabled: false },
      { name: 'G', disabled: false }, { name: 'H', disabled: false },
      { name: 'L', disabled: false }, { name: '警', disabled: true },
      { name: 'Z', disabled: false }, { name: 'X', disabled: false },
      { name: 'C', disabled: false }, { name: 'V', disabled: false },
      { name: 'B', disabled: false }, { name: 'N', disabled: false },
      { name: 'M', disabled: false }, { name: '港', disabled: true },
      { name: '澳', disabled: true }
    ],

    keyboard3: [
      { name: '1', disabled: false }, { name: '2', disabled: false },
      { name: '3', disabled: false }, { name: '4', disabled: false },
      { name: '5', disabled: false }, { name: '6', disabled: false },
      { name: '7', disabled: false }, { name: '8', disabled: false },
      { name: '9', disabled: false }, { name: '0', disabled: false },
      { name: 'Q', disabled: false }, { name: 'W', disabled: false },
      { name: 'E', disabled: false }, { name: 'R', disabled: false },
      { name: 'T', disabled: false }, { name: 'Y', disabled: false },
      { name: 'U', disabled: false }, { name: 'O', disabled: true },
      { name: 'P', disabled: false }, { name: '军', disabled: true },
      { name: 'A', disabled: false }, { name: 'S', disabled: false },
      { name: 'D', disabled: false }, { name: 'F', disabled: false },
      { name: 'J', disabled: false }, { name: 'K', disabled: false },
      { name: 'G', disabled: false }, { name: 'H', disabled: false },
      { name: 'L', disabled: false }, { name: '警', disabled: true },
      { name: 'Z', disabled: false }, { name: 'X', disabled: false },
      { name: 'C', disabled: false }, { name: 'V', disabled: false },
      { name: 'B', disabled: false }, { name: 'N', disabled: false },
      { name: 'M', disabled: false }, { name: '港', disabled: true },
      { name: '澳', disabled: true }
    ],

    keyboard4: [
      { name: '1', disabled: false }, { name: '2', disabled: false },
      { name: '3', disabled: false }, { name: '4', disabled: false },
      { name: '5', disabled: false }, { name: '6', disabled: false },
      { name: '7', disabled: false }, { name: '8', disabled: false },
      { name: '9', disabled: false }, { name: '0', disabled: false },
      { name: 'Q', disabled: false }, { name: 'W', disabled: false },
      { name: 'E', disabled: false }, { name: 'R', disabled: false },
      { name: 'T', disabled: false }, { name: 'Y', disabled: false },
      { name: 'U', disabled: false }, { name: 'O', disabled: false },
      { name: 'P', disabled: false }, { name: '军', disabled: false },
      { name: 'A', disabled: false }, { name: 'S', disabled: false },
      { name: 'D', disabled: false }, { name: 'F', disabled: false },
      { name: 'J', disabled: false }, { name: 'K', disabled: false },
      { name: 'G', disabled: false }, { name: 'H', disabled: false },
      { name: 'L', disabled: false }, { name: '警', disabled: false },
      { name: 'Z', disabled: false }, { name: 'X', disabled: false },
      { name: 'C', disabled: false }, { name: 'V', disabled: false },
      { name: 'B', disabled: false }, { name: 'N', disabled: false },
      { name: 'M', disabled: false }, { name: '港', disabled: false },
      { name: '澳', disabled: false }
    ],

    carNumArr: ['', '', '', '', '', '', ''],
    cansave: false
  },

  ready() {
    // var m = this
    // var carnumok = wx.getStorageSync('carnum') 
    // m.setData({
    //   newcarnum :''
    // })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    carnum(){
      this.triggerEvent('carnum','1')
    },
    //选择车牌
    choosedText: function (e) {
      let text = e.currentTarget.dataset.text;
      let itemActiveIndex = this.data.itemActiveIndex;
      this.setData({
        [`carNumArr[${itemActiveIndex}]`]: text
      })
      if (itemActiveIndex < 6) {
        itemActiveIndex += 1
        this.setData({
          itemActiveIndex
        })
      }
      let cansave = this.data.carNumArr.every(val => {
        return val != ''
      })
      if (cansave) {
        this.setData({
          cansave: true
        })
      }
      console.log(cansave)
    },

    //删除当前框的值
    delCarNumSelect: function () {
      let itemActiveIndex = this.data.itemActiveIndex;
      this.setData({
        [`carNumArr[${itemActiveIndex}]`]: ''
      })
      if (itemActiveIndex > 0) {
        itemActiveIndex -= 1
        this.setData({
          itemActiveIndex, cansave: false
        })
      }
    },

    saveCarNum: function () {
      this.triggerEvent('carnum',1 )
      let carNumArr = this.data.carNumArr;
      let p = this
      carNumArr = carNumArr.join('');
      console.log(carNumArr) 
      wx.setStorageSync('carnum',carNumArr)
    var carnumok = wx.getStorageSync('carnum') 
          p.setData({
            newcarnum :carnumok
          })
     
          wx.request({
            url: 'https://dishichuxing.cn/api.php/?s=driver/licensePlateNumBindingDrivingOrder',
            method:"POST",
            data:{
              access_token:wx.getStorageSync('access_token'),
              _uniacid: 1,
              _acid: 1,
              oid:wx.getStorageSync('oid'),
              // uid: wx.getStorageSync('uid') ,
              license_plate_num : carnumok
            },
            success:function(e){
              console.log(e);
            }
            
          })
     wx.showToast({
        title: '保存成功',
      }) && this.setData({
        showAddCarNum: false,
        carNumArr: ['', '', '', '', '', '', ''],
        itemActiveIndex: 0
      }),
      
      wx.redirectTo({
        url: 'pages/index/index',
      })
    

    },

    //选择输入框
    itemActive: function (e) {
      let index = e.currentTarget.dataset.index;
      this.setData({ itemActiveIndex: index })
    },

    //点击显示新增车牌
    showAddCarNumFun: function () {
      this.setData({ showAddCarNum: true })
     
    },

    //点击取消新增车牌
    closeAddCarNum: function () {
      this.setData({
        showAddCarNum: false,
        carNumArr: ['', '', '', '', '', '', ''],
        itemActiveIndex: 0
      })
    }
  }
})
